package com.example.multiple.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.multiple.annotation.DataSource;
import com.example.multiple.domain.slave.Product;
import com.example.multiple.enums.DataSourceType;
import com.example.multiple.mapper.slave.ProductMapper;
import com.example.multiple.service.slave.ProductService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@DataSource(DataSourceType.SLAVE)
public class TestService {

    @Resource
    private ProductService productService;

    @Resource
    private ProductMapper productMapper;

    public void run(){
        List<Product> productList = productMapper.selectList(new QueryWrapper<>());
        System.out.println("第一次查询");
        System.out.println(productList);
        Product product = productService.selectProductByName("产品");
        System.out.println("第二次查询");
        System.out.println(product);
        productList = productMapper.selectList(new QueryWrapper<>());
        System.out.println("第三次查询");
        System.out.println(productList);
    }
}
